﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmQuanLyDichVu : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmQuanLyDichVu()
        {
            InitializeComponent();
        }
        private void frmQuanLyDichVu_Load(object sender, EventArgs e)
        {
            tabAll_Click(null, null);
            XuLyDataGridView.Style(dgrDanhSach);
        }
       
        private void tabThem_Click(object sender, EventArgs e)
        {
            txtMaDV.Enabled = true;
            tabView.Visible = false;
            TabConTrol.Height = 159;
            this.tabThem.AttachedControl = this.tabpnInfo;
            btnLamLai_Click(null, null);
            btnSua.Enabled = btnXoa.Enabled = false;
            btnThem.Enabled = true;
        }
        private void tabTimKiem_Click(object sender, EventArgs e)
        {
            tabView.Visible = false;
            TabConTrol.Height = 100;
            switch (cbChoose.SelectedIndex)
            {
                case 0:
                    dgrDanhSach.DataSource = DichVu_Info.GetByID(int.Parse(txtSearch.Text));
                    break;
                case 1:
                    dgrDanhSach.DataSource =DichVu_Info.GetByName(txtSearch.Text);
                    break; 
            }

        }
        private void tabView_Click(object sender, EventArgs e)
        {
            this.tabView.AttachedControl = this.tabpnInfo;
            tabView.Visible = true;
            TabConTrol.SelectedTab = tabView;
            TabConTrol.Height = 159;
            btnSua.Enabled = btnXoa.Enabled = true;
            btnThem.Enabled = false;
        }
        void BinGidToForm(DataGridViewRow r)
        {
            try
            {
                txtMaDV.Text = r.Cells["MADV"].Value.ToString();
                txtTenDV.Text = r.Cells["TENDV"].Value.ToString();
                txtGiaDichVu.Text = r.Cells["GIA"].Value.ToString();
                txtDonViTinh.Text = r.Cells["DONVITINH"].Value.ToString();
            }
            catch (Exception)
            {
            }
        }
      
        private void dgrDanhSach_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                txtMaDV.Enabled = false;
                BinGidToForm(dgrDanhSach.CurrentRow);
                tabView_Click(null, null);
            }
            catch (Exception)
            {
            }
        }
       
   

        private void btnInAn_Click(object sender, EventArgs e)
        {
            frmFormMain frm = MdiParent as frmFormMain;

            frm.pr.NhanVien_GetByIDBindingSource.DataSource = NhanVien_Info.GetByMaSo(txtMaDV.Text).Tables[0];
            frm.pr.rpViewer.RefreshReport();
            frm.pr.Text = "THÔNG TIN NHÂN VIÊN " + txtTenDV.Text;
            frm.ShowPrint();

        }

        private void tabAll_Click(object sender, EventArgs e)
        {

            TabConTrol.SelectedTab = tabAll;
            dgrDanhSach.DataSource = DichVu_Info.GetAll().Tables[0];
            tabView.Visible = false;
            TabConTrol.Height = 26;
        }

        

        private void btnSua_Click(object sender, EventArgs e)
        {

            if (DichVu_Info.Update(int.Parse(txtMaDV.Text), txtTenDV.Text, float.Parse(txtGiaDichVu.Text), txtDonViTinh.Text))
            {
                BatLoi.ThongBao("Update Dịch Vụ Thành Công");
                tabAll_Click(null, null);
            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (DichVu_Info.Add(int.Parse(txtMaDV.Text), txtTenDV.Text, float.Parse(txtGiaDichVu.Text), txtDonViTinh.Text))
            {
                BatLoi.ThongBao("Thêm Dịch Vụ Thành Công");
                tabAll_Click(null, null);
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (DichVu_Info.Delete(txtMaDV.Text))
            {
                BatLoi.ThongBao("Xóa Dịch Vụ Thành Công");
                tabAll_Click(null, null);
            }
        }

        private void btnLamLai_Click(object sender, EventArgs e)
        {
            try
            {

                if (!tabView.Visible)
                {
                    txtMaDV.Text =
                    txtTenDV.Text =
                    txtDonViTinh.Text =
                    txtGiaDichVu.Text = "";


                }
                else
                    BinGidToForm(dgrDanhSach.CurrentRow);
            }
            catch (Exception)
            {
            }
        }

        private void btnXoaSelectItem_Click(object sender, EventArgs e)
        {
            if (BatLoi.DgResult("Bạn có muốn xóa những nhân viên được chọn"))
            {
                foreach (DataGridViewRow r in dgrDanhSach.SelectedRows)
                    NhanVien_Info.Delete(r.Cells["manv"].Value.ToString());
            }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            switch (cbChoose.SelectedIndex)
            {
                case 0:
                    dgrDanhSach.DataSource =DichVu_Info.GetByID(int.Parse(txtSearch.Text));
                    break;
                case 1:
                    dgrDanhSach.DataSource = DichVu_Info.GetByName(txtSearch.Text);
              
                    break;
            }
        }


       
      

       

      
       

     

       
    }
}
